package com.xiaomazi.edu.controller;

import com.xiaomazi.common.utils.R;
import com.xiaomazi.edu.dto.TeacherQuery;
import com.xiaomazi.edu.service.TeacherService;
import com.xiaomazi.edu.entity.Teacher;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: llxy-parent
 * @description: 讲师前端控制器
 * @author: 小马子
 * @create: 2023-02-08 23:06
 **/
@Api(tags = "讲师管理")
@RestController
@RequestMapping("/eduservice/teacher")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;


    @ApiOperation(value = "所有讲师列表")
    @GetMapping("/findAll")
    public R findAll(){
        return R.ok().data("items",teacherService.list());
    }

    @ApiOperation("逻辑删除讲师")
    @PostMapping("{id}")
    public R deleteById(@ApiParam(name = "id",value = "讲师Id",required = true)
                            @PathVariable String id){
        return teacherService.removeById(id) ? R.ok() : R.error();
    }

    @ApiOperation(value = "条件查询带分页查询讲师")
    @PostMapping("/pageTeacherCondition")
    public R pageListTeacher(@RequestBody TeacherQuery teacherQuery){
        return teacherService.pageListTeacherByQuery(teacherQuery);
    }


    @ApiOperation(value = "添加讲师")
    @PostMapping("addTeacher")
    public R addTeacher(@RequestBody Teacher teacher){
        return teacherService.save(teacher) ? R.ok() : R.error();
    }

    @ApiOperation(value = "根据Id查询出一位讲师")
    @GetMapping("getTeacher/{id}")
    public R getTeacherById(@PathVariable String id){
        return R.ok().data("teacher",teacherService.getById(id));
    }

    @ApiOperation(value = "修改讲师信息")
    @PostMapping("updateTeacher")
    public R updateTeacher(@RequestBody Teacher teacher){
        return teacherService.updateById(teacher) ? R.ok() : R.error();
    }

}
